package firing;

import game.Bullet;
import game.Enemy;
import game.Player;

import java.util.List;

public class ChangeAngleNode extends AbstractUnaryNode {

    private static final long serialVersionUID = -4941492784304159063L;
    /** Change the angle of fire by this amount (radians) */
    private static double[] angles = {3,5,10,20,30};
    private double angleOffset;
    
    public ChangeAngleNode() {
	super();
	randomizeNode();
    }
    
    public void calculate(List<Bullet> bullets, double angle, Enemy shooter, Player player) {
	if (child != null) {
	    child.calculate(bullets, angle + angleOffset, shooter, player);
	}
    }
    
    public double getAngle() {
	return angleOffset;
    }
    
    public void setAngle(double angle) {
	this.angleOffset = angle;
    }

    @Override
    public void randomizeNode() {
	angleOffset = Math.toRadians((Math.random() * 2 > 1)? 1.0:-1.0) * angles[(int)(Math.random()*5)];
    }
    
    public String toString() {
	return ("Change Angle: " + Math.toDegrees(angleOffset));
    }

    @Override
    public Node duplicate() {
	ChangeAngleNode duplicate = new ChangeAngleNode();	
	if (child != null) {
	    duplicate.setChild(child.duplicate());
	}
	duplicate.angleOffset = angleOffset;
	return duplicate;
    }
}
